package com.xinqi.modules.prepare.question.factory;

import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.prepare.question.client.PrepareQuestionFolderClient;
import com.xinqi.modules.prepare.question.dto.req.PrepareQuestionFolderCreateDTO;
import com.xinqi.modules.prepare.question.dto.req.PrepareQuestionFolderQueryDTO;
import com.xinqi.modules.prepare.question.dto.req.PrepareQuestionFolderUpdateDTO;
import com.xinqi.modules.prepare.question.dto.rsp.PrepareQuestionFolderResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 备课区试题夹降级处理
 *
 * @author: system
 * @date: 2023/03/19
 */
@Slf4j
@Component
public class PrepareQuestionFolderFallbackFactory implements FallbackFactory<PrepareQuestionFolderClient> {

    @Override
    public PrepareQuestionFolderClient create(Throwable throwable) {
        log.error("日志服务调用失败:{}", throwable.getMessage());
        return new PrepareQuestionFolderClient() {
            @Override
            public R<PageInfo<PrepareQuestionFolderResultDTO>> page(PrepareQuestionFolderQueryDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<PrepareQuestionFolderResultDTO> findById(Long id) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Long> insert(PrepareQuestionFolderCreateDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Boolean> update(Long id, PrepareQuestionFolderUpdateDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Boolean> delete(Long id) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }
        };
    }
}
